Note
Click here to download the full example code
Callosal bundles using AFQ API¶
An example using the AFQ API to find callosal bundles using the templates from: http://hdl.handle.net/1773/34926
import os.path as op
import plotly
from AFQ import api
from AFQ.definitions.mask import RoiMask
import AFQ.data as afd
Get some example data¶
Retrieves Stanford HARDI dataset.
afd.organize_stanford_data(clear_previous_afq=True)
Set tractography parameters (optional)¶
We make this tracking_params which we will pass to the AFQ object which specifies that we want 100,000 seeds randomly distributed in the ROIs of every bundle.
We only do this to make this example faster and consume less space.
tracking_params = dict(seed_mask=RoiMask(),
n_seeds=10000,
random_seeds=True,
rng_seed=42)
Initialize an AFQ object:¶
We specify bundle_info as the default bundles list (api.BUNDLES) plus the callosal bundle list. This tells the AFQ object to use bundles from both the standard and callosal templates.
myafq = api.AFQ(bids_path=op.join(afd.afq_home,
'stanford_hardi'),
dmriprep='vistasoft',
bundle_info=api.BUNDLES + api.CALLOSUM_BUNDLES,
tracking_params=tracking_params)
Visualizing bundles and tract profiles:¶
This would run the script and visualize the bundles using the plotly interactive visualization, which should automatically open in a new browser window.
bundle_html = myafq.viz_bundles(export=True, n_points=50)
plotly.io.show(bundle_html[0])
Out:
Optimizing level 2 [max iter: 10000]
Optimizing level 1 [max iter: 1000]
Optimizing level 0 [max iter: 100]
Optimizing level 2 [max iter: 10000]
Optimizing level 1 [max iter: 1000]
Optimizing level 0 [max iter: 100]
Optimizing level 2 [max iter: 10000]
Optimizing level 1 [max iter: 1000]
Optimizing level 0 [max iter: 100]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 3358.13 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 3320.91 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 15.01 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 3081.78 MB/s]
0%| | 0/29 [00:00<?, ? MB/s]
14%|#3 | 4/29 [00:00<00:00, 30.20 MB/s]
52%|#####1 | 15/29 [00:00<00:00, 61.12 MB/s]
100%|##########| 29/29 [00:00<00:00, 108.41 MB/s]
0%| | 0/28 [00:00<?, ? MB/s]
11%|# | 3/28 [00:00<00:01, 22.55 MB/s]
36%|###5 | 10/28 [00:00<00:00, 40.09 MB/s]
100%|##########| 28/28 [00:00<00:00, 83.58 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 2826.35 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 3192.01 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 2912.71 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 2955.82 MB/s]
0%| | 0/23 [00:00<?, ? MB/s]
17%|#7 | 4/23 [00:00<00:00, 30.09 MB/s]
48%|####7 | 11/23 [00:00<00:00, 43.18 MB/s]
100%|##########| 23/23 [00:00<00:00, 68.87 MB/s]
0%| | 0/22 [00:00<?, ? MB/s]
18%|#8 | 4/22 [00:00<00:00, 30.10 MB/s]
45%|####5 | 10/22 [00:00<00:00, 38.86 MB/s]
100%|##########| 22/22 [00:00<00:00, 65.96 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 2365.65 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 2972.58 MB/s]
0%| | 0/2 [00:00<?, ? MB/s]
100%|##########| 2/2 [00:00<00:00, 30.15 MB/s]
0%| | 0/2 [00:00<?, ? MB/s]
100%|##########| 2/2 [00:00<00:00, 29.90 MB/s]
0%| | 0/24 [00:00<?, ? MB/s]
17%|#6 | 4/24 [00:00<00:00, 30.13 MB/s]
54%|#####4 | 13/24 [00:00<00:00, 52.02 MB/s]
100%|##########| 24/24 [00:00<00:00, 89.67 MB/s]
0%| | 0/24 [00:00<?, ? MB/s]
17%|#6 | 4/24 [00:00<00:00, 30.04 MB/s]
62%|######2 | 15/24 [00:00<00:00, 60.76 MB/s]
100%|##########| 24/24 [00:00<00:00, 88.83 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 3374.34 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 3204.20 MB/s]
0%| | 0/28 [00:00<?, ? MB/s]
14%|#4 | 4/28 [00:00<00:00, 29.83 MB/s]
43%|####2 | 12/28 [00:00<00:00, 47.18 MB/s]
100%|##########| 28/28 [00:00<00:00, 83.08 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 3504.01 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 3246.37 MB/s]
0%| | 0/25 [00:00<?, ? MB/s]
16%|#6 | 4/25 [00:00<00:00, 29.17 MB/s]
36%|###6 | 9/25 [00:00<00:00, 33.61 MB/s]
100%|##########| 25/25 [00:00<00:00, 73.23 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 15.00 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 3527.59 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 2396.75 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 2720.04 MB/s]
0%| | 0/21 [00:00<?, ? MB/s]
14%|#4 | 3/21 [00:00<00:00, 22.46 MB/s]
52%|#####2 | 11/21 [00:00<00:00, 44.37 MB/s]
100%|##########| 21/21 [00:00<00:00, 78.09 MB/s]
0%| | 0/21 [00:00<?, ? MB/s]
19%|#9 | 4/21 [00:00<00:00, 30.28 MB/s]
52%|#####2 | 11/21 [00:00<00:00, 43.46 MB/s]
100%|##########| 21/21 [00:00<00:00, 78.81 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 2699.04 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 3019.66 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 2908.67 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 2219.21 MB/s]
0%| | 0/29 [00:00<?, ? MB/s]
14%|#3 | 4/29 [00:00<00:00, 30.34 MB/s]
41%|####1 | 12/29 [00:00<00:00, 48.00 MB/s]
100%|##########| 29/29 [00:00<00:00, 87.55 MB/s]
0%| | 0/29 [00:00<?, ? MB/s]
14%|#3 | 4/29 [00:00<00:00, 29.97 MB/s]
34%|###4 | 10/29 [00:00<00:00, 38.69 MB/s]
100%|##########| 29/29 [00:00<00:00, 86.44 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 2935.13 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 3123.09 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 3724.96 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 3858.61 MB/s]
0%| | 0/28 [00:00<?, ? MB/s]
14%|#4 | 4/28 [00:00<00:00, 30.26 MB/s]
39%|###9 | 11/28 [00:00<00:00, 43.38 MB/s]
100%|##########| 28/28 [00:00<00:00, 84.16 MB/s]
0%| | 0/27 [00:00<?, ? MB/s]
15%|#4 | 4/27 [00:00<00:00, 30.05 MB/s]
37%|###7 | 10/27 [00:00<00:00, 38.77 MB/s]
100%|##########| 27/27 [00:00<00:00, 80.49 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 3748.26 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 3474.98 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 2781.37 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 3054.85 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 15.06 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 3204.20 MB/s]
0%| | 0/32 [00:00<?, ? MB/s]
9%|9 | 3/32 [00:00<00:01, 22.45 MB/s]
34%|###4 | 11/32 [00:00<00:00, 44.32 MB/s]
100%|##########| 32/32 [00:00<00:00, 95.16 MB/s]
0%| | 0/30 [00:00<?, ? MB/s]
13%|#3 | 4/30 [00:00<00:00, 29.88 MB/s]
43%|####3 | 13/30 [00:00<00:00, 51.62 MB/s]
100%|##########| 30/30 [00:00<00:00, 89.12 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 2206.37 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 2511.56 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 3371.63 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 3289.65 MB/s]
0%| | 0/23 [00:00<?, ? MB/s]
13%|#3 | 3/23 [00:00<00:00, 22.53 MB/s]
52%|#####2 | 12/23 [00:00<00:00, 48.79 MB/s]
100%|##########| 23/23 [00:00<00:00, 85.55 MB/s]
0%| | 0/22 [00:00<?, ? MB/s]
18%|#8 | 4/22 [00:00<00:00, 30.00 MB/s]
50%|##### | 11/22 [00:00<00:00, 43.02 MB/s]
100%|##########| 22/22 [00:00<00:00, 81.79 MB/s]
0%| | 0/26 [00:00<?, ? MB/s]
15%|#5 | 4/26 [00:00<00:00, 30.13 MB/s]
54%|#####3 | 14/26 [00:00<00:00, 56.35 MB/s]
100%|##########| 26/26 [00:00<00:00, 96.96 MB/s]
0%| | 0/23 [00:00<?, ? MB/s]
17%|#7 | 4/23 [00:00<00:00, 30.07 MB/s]
52%|#####2 | 12/23 [00:00<00:00, 47.67 MB/s]
100%|##########| 23/23 [00:00<00:00, 85.93 MB/s]
0%| | 0/2 [00:00<?, ? MB/s]
100%|##########| 2/2 [00:00<00:00, 33.71 MB/s]
0%| | 0/2 [00:00<?, ? MB/s]
100%|##########| 2/2 [00:00<00:00, 30.38 MB/s]
0%| | 0/2 [00:00<?, ? MB/s]
100%|##########| 2/2 [00:00<00:00, 30.06 MB/s]
0%| | 0/2 [00:00<?, ? MB/s]
100%|##########| 2/2 [00:00<00:00, 30.63 MB/s]
0%| | 0/2 [00:00<?, ? MB/s]
100%|##########| 2/2 [00:00<00:00, 30.18 MB/s]
0%| | 0/2 [00:00<?, ? MB/s]
100%|##########| 2/2 [00:00<00:00, 30.28 MB/s]
0%| | 0/2 [00:00<?, ? MB/s]
100%|##########| 2/2 [00:00<00:00, 30.21 MB/s]
0%| | 0/2 [00:00<?, ? MB/s]
100%|##########| 2/2 [00:00<00:00, 30.09 MB/s]
0%| | 0/2 [00:00<?, ? MB/s]
100%|##########| 2/2 [00:00<00:00, 30.61 MB/s]
0%| | 0/2 [00:00<?, ? MB/s]
100%|##########| 2/2 [00:00<00:00, 29.94 MB/s]
0%| | 0/2 [00:00<?, ? MB/s]
100%|##########| 2/2 [00:00<00:00, 1014.96 MB/s]
0%| | 0/2 [00:00<?, ? MB/s]
100%|##########| 2/2 [00:00<00:00, 30.13 MB/s]
0%| | 0/2 [00:00<?, ? MB/s]
100%|##########| 2/2 [00:00<00:00, 6898.53 MB/s]
0%| | 0/2 [00:00<?, ? MB/s]
100%|##########| 2/2 [00:00<00:00, 30.14 MB/s]
0%| | 0/2 [00:00<?, ? MB/s]
100%|##########| 2/2 [00:00<00:00, 3728.27 MB/s]
0%| | 0/2 [00:00<?, ? MB/s]
100%|##########| 2/2 [00:00<00:00, 30.16 MB/s]
0%| | 0/2 [00:00<?, ? MB/s]
100%|##########| 2/2 [00:00<00:00, 6340.60 MB/s]
0%| | 0/15 [00:00<?, ? MB/s]
20%|## | 3/15 [00:00<00:00, 24.58 MB/s]
87%|########6 | 13/15 [00:00<00:00, 57.24 MB/s]
100%|##########| 15/15 [00:00<00:00, 60.34 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 4981.36 MB/s]
0%| | 0/1415 [00:00<?, ?it/s]
0%| | 1/1415 [00:00<02:45, 8.55it/s]
0%| | 2/1415 [00:00<09:06, 2.58it/s]
0%| | 4/1415 [00:06<42:42, 1.82s/it]
1%| | 14/1415 [00:06<07:55, 2.94it/s]
73%|#######3 | 1040/1415 [00:06<00:01, 343.24it/s]
100%|##########| 1415/1415 [00:06<00:00, 227.06it/s]
0%| | 0/1156 [00:00<?, ?it/s]
88%|########8 | 1020/1156 [00:00<00:00, 8467.94it/s]
100%|##########| 1156/1156 [00:00<00:00, 9571.27it/s]
0%| | 0/532 [00:00<?, ?it/s]
95%|#########5| 508/532 [00:00<00:00, 4391.69it/s]
100%|##########| 532/532 [00:00<00:00, 4584.97it/s]
0%| | 0/304 [00:00<?, ?it/s]
100%|##########| 304/304 [00:00<00:00, 4292.21it/s]
0%| | 0/580 [00:00<?, ?it/s]
100%|##########| 580/580 [00:00<00:00, 7276.64it/s]
0%| | 0/546 [00:00<?, ?it/s]
93%|#########3| 508/546 [00:00<00:00, 4968.64it/s]
100%|##########| 546/546 [00:00<00:00, 5323.08it/s]
0%| | 0/1377 [00:00<?, ?it/s]
27%|##7 | 372/1377 [00:00<00:00, 3452.69it/s]
73%|#######3 | 1012/1377 [00:00<00:00, 4025.73it/s]
100%|##########| 1377/1377 [00:00<00:00, 5369.65it/s]
0%| | 0/1232 [00:00<?, ?it/s]
31%|### | 380/1232 [00:00<00:00, 3357.65it/s]
83%|########2 | 1020/1232 [00:00<00:00, 4382.70it/s]
100%|##########| 1232/1232 [00:00<00:00, 5110.93it/s]
0%| | 0/1190 [00:00<?, ?it/s]
21%|## | 248/1190 [00:00<00:00, 2096.78it/s]
64%|######3 | 760/1190 [00:00<00:00, 3045.43it/s]
89%|########8 | 1058/1190 [00:00<00:00, 2679.23it/s]
100%|##########| 1190/1190 [00:00<00:00, 3022.38it/s]
0%| | 0/998 [00:00<?, ?it/s]
25%|##5 | 252/998 [00:00<00:00, 2061.32it/s]
77%|#######6 | 764/998 [00:00<00:00, 3270.44it/s]
100%|##########| 998/998 [00:00<00:00, 4031.14it/s]
0%| | 0/1795 [00:00<?, ?it/s]
28%|##8 | 508/1795 [00:00<00:00, 4699.62it/s]
85%|########5 | 1532/1795 [00:00<00:00, 5769.98it/s]
100%|##########| 1795/1795 [00:00<00:00, 6601.09it/s]
0%| | 0/1665 [00:00<?, ?it/s]
22%|##2 | 372/1665 [00:00<00:00, 3428.64it/s]
61%|###### | 1012/1665 [00:00<00:00, 4595.86it/s]
100%|##########| 1665/1665 [00:00<00:00, 5678.39it/s]
0%| | 0/1376 [00:00<?, ?it/s]
37%|###6 | 508/1376 [00:00<00:00, 4340.08it/s]
100%|##########| 1376/1376 [00:00<00:00, 7006.65it/s]
0%| | 0/1351 [00:00<?, ?it/s]
38%|###7 | 508/1351 [00:00<00:00, 3986.31it/s]
100%|##########| 1351/1351 [00:00<00:00, 6683.13it/s]
0%| | 0/579 [00:00<?, ?it/s]
66%|######5 | 380/579 [00:00<00:00, 3796.61it/s]
100%|##########| 579/579 [00:00<00:00, 4809.79it/s]
0%| | 0/702 [00:00<?, ?it/s]
100%|##########| 702/702 [00:00<00:00, 7813.94it/s]
0%| | 0/5570 [00:00<?, ?it/s]
14%|#3 | 764/5570 [00:00<00:00, 5928.15it/s]
28%|##7 | 1532/5570 [00:00<00:00, 6759.65it/s]
40%|###9 | 2217/5570 [00:00<00:00, 6578.18it/s]
55%|#####5 | 3068/5570 [00:00<00:00, 6971.41it/s]
73%|#######3 | 4092/5570 [00:00<00:00, 5871.02it/s]
92%|#########1| 5116/5570 [00:00<00:00, 5508.75it/s]
100%|##########| 5570/5570 [00:00<00:00, 6414.49it/s]
0%| | 0/5570 [00:00<?, ?it/s]
18%|#8 | 1020/5570 [00:00<00:00, 8652.58it/s]
55%|#####5 | 3068/5570 [00:00<00:00, 13345.83it/s]
100%|##########| 5570/5570 [00:00<00:00, 16609.78it/s]
0%| | 0/5570 [00:00<?, ?it/s]
14%|#3 | 764/5570 [00:00<00:00, 6418.40it/s]
37%|###6 | 2044/5570 [00:00<00:00, 6646.12it/s]
63%|######3 | 3527/5570 [00:00<00:00, 9456.92it/s]
82%|########1 | 4564/5570 [00:00<00:00, 7353.55it/s]
97%|#########6| 5397/5570 [00:00<00:00, 6043.46it/s]
100%|##########| 5570/5570 [00:00<00:00, 6895.66it/s]
0%| | 0/5570 [00:00<?, ?it/s]
18%|#8 | 1020/5570 [00:00<00:00, 8226.94it/s]
55%|#####5 | 3068/5570 [00:00<00:00, 12047.25it/s]
76%|#######6 | 4253/5570 [00:00<00:00, 11225.54it/s]
100%|##########| 5570/5570 [00:00<00:00, 14462.73it/s]
0%| | 0/5570 [00:00<?, ?it/s]
14%|#3 | 764/5570 [00:00<00:00, 7075.04it/s]
37%|###6 | 2044/5570 [00:00<00:00, 7534.83it/s]
73%|#######3 | 4092/5570 [00:00<00:00, 7890.98it/s]
92%|#########1| 5116/5570 [00:00<00:00, 7226.05it/s]
100%|##########| 5570/5570 [00:00<00:00, 8020.64it/s]
0%| | 0/5570 [00:00<?, ?it/s]
7%|6 | 380/5570 [00:00<00:01, 3470.81it/s]
18%|#8 | 1020/5570 [00:00<00:01, 3708.35it/s]
37%|###6 | 2044/5570 [00:00<00:00, 3934.67it/s]
46%|####5 | 2556/5570 [00:00<00:00, 3623.68it/s]
55%|#####5 | 3068/5570 [00:00<00:00, 3460.14it/s]
64%|######4 | 3580/5570 [00:01<00:00, 3234.40it/s]
73%|#######3 | 4092/5570 [00:01<00:00, 3229.67it/s]
83%|########2 | 4604/5570 [00:01<00:00, 3204.57it/s]
92%|#########1| 5116/5570 [00:01<00:00, 3126.43it/s]
100%|##########| 5570/5570 [00:01<00:00, 3628.74it/s]
0%| | 0/5570 [00:00<?, ?it/s]
14%|#3 | 764/5570 [00:00<00:00, 7273.05it/s]
37%|###6 | 2044/5570 [00:00<00:00, 7669.24it/s]
73%|#######3 | 4092/5570 [00:00<00:00, 8395.68it/s]
92%|#########1| 5116/5570 [00:00<00:00, 7780.87it/s]
100%|##########| 5570/5570 [00:00<00:00, 8547.80it/s]
0%| | 0/5570 [00:00<?, ?it/s]
14%|#3 | 764/5570 [00:00<00:00, 6704.93it/s]
37%|###6 | 2044/5570 [00:00<00:00, 7426.43it/s]
73%|#######3 | 4092/5570 [00:00<00:00, 8148.92it/s]
92%|#########1| 5116/5570 [00:00<00:00, 7528.63it/s]
100%|##########| 5570/5570 [00:00<00:00, 8256.27it/s]
Total running time of the script: ( 20 minutes 29.110 seconds)